package com.smile.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.smile.api.OperateLogApi;
import com.smile.api.OrganizationApi;
import com.smile.api.OssApi;
import com.smile.mapper.*;
import com.smile.model.domain.*;
import com.smile.model.dto.request.GetAirportByIdRequestDTO;
import com.smile.model.dto.request.TaskRequestDTO;
import com.smile.model.response.response.GetAirportByIdResponseDTO;
import com.smile.model.response.response.GetAirportListResponseDTO;
import com.smile.service.AirportService;
import com.smile.service.SituationScreenService;
import com.smile.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

@Service
@Slf4j
public class TaskServiceImpl implements TaskService {

    @Autowired
    private OssApi ossApi;

    @Autowired
    private AirportMapper airportMapper;

    @Autowired
    private InspectionTaskMapper inspectionTaskMapper;

    @Autowired
    private WayPointTaskInfoMapper wayPointTaskInfoMapper;

    @Autowired
    private WayPointMapper wayPointMapper;

    @Autowired
    private WayPointActionMapper wayPointActionMapper;


    @Autowired
    private AirportService airportService;

    @Override
    public Map<String,Object> Info(TaskRequestDTO taskRequestDTO) throws IOException {
        Map<String,Object> map = new HashMap<>();
        QueryWrapper<FeisuanInspectionTask> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("flight_id",taskRequestDTO.getFlightId());
        FeisuanInspectionTask feisuanInspectionTask = inspectionTaskMapper.selectOne(queryWrapper);
        if (ObjectUtil.isNotNull(feisuanInspectionTask)) {
            GetAirportByIdRequestDTO  getAirportByIdRequestDTO = new GetAirportByIdRequestDTO();
            getAirportByIdRequestDTO.setId(feisuanInspectionTask.getAirportId());
//            GetAirportByIdResponseDTO getAirportById(GetAirportByIdRequestDTO getAirportByIdRequestDTO);
            GetAirportByIdResponseDTO getAirportByIdResponseDTO = airportService.getAirportById(getAirportByIdRequestDTO);
            map.put("airport",getAirportByIdResponseDTO);//机场信息
            QueryWrapper<FeisuanWayPointTaskInfo> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("flight_id",taskRequestDTO.getFlightId());
            List<FeisuanWayPointTaskInfo> list = wayPointTaskInfoMapper.selectList(queryWrapper1);
            map.put("process",list);
            map.put("wayPoint",list.size());//航点数
            map.put("task_time",100000);//飞行时长
            map.put("task_distance",100000);//飞行距离

        }
        return map;
    }
}
